package vip.specimen.system.datasource.validation.implement;

import org.springframework.beans.factory.annotation.Autowired;
import vip.specimen.system.datasource.entity.SystemUserEntity;
import vip.specimen.system.datasource.validation.annotation.UserNameUnique;
import vip.specimen.system.service.SystemUserService;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * *@Author: 余浪人
 * *@Date：2021/3/24 15:58
 * *@Email:yulangren520@Gmail.com
 * *@QQ:1368419640
 **/
public class UserNameUniqueImp implements ConstraintValidator<UserNameUnique, String> {
    @Autowired
    private SystemUserService userService;

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        SystemUserEntity userEntity = this.userService.findByUsername(s);
        return null == userEntity;
    }
}
